package com.cne.gmail.Gmail.Util;


import com.cne.gmail.Gmail.Handle.GmailHandle;
import com.cne.gmail.Gmail.model.UserModel;
import com.google.api.services.gmail.model.Message;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.stream.Collectors;

public class MakeGmailIdsUtil {

    public static List<String> makeGmailIds(UserModel user, List labels) throws GeneralSecurityException, IOException {
        List<String> gmailIds =  GmailHandle.service(user)
                                            .users()
                                            .messages()
                                            .list("me")
                                            .setMaxResults(Long.valueOf(100))
                                            .setLabelIds(labels)
                                            .execute()
                                            .getMessages()
                                            .stream()
                                            .map(Message::getId)
                                            .collect(Collectors.toList());
        return gmailIds;
    }
}
